package com.learn2.config;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration.Dynamic;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

/**
 * @Author:Mark
 * @Description:
 * @Date: Created on 9:41 2018-11-15
 * @Modify by:
 */
@ComponentScan("com.learn2.*")
public class MyWebConfig implements WebApplicationInitializer {

  @Override
  public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext webApplicationContext=new AnnotationConfigWebApplicationContext();
    webApplicationContext.register(MyWebConfig.class);
    webApplicationContext.setServletContext(servletContext);
    Dynamic dynamic = servletContext.addServlet("dispatcher", new DispatcherServlet(webApplicationContext));
    dynamic.addMapping("*.do");
    dynamic.setLoadOnStartup(1);


  }
}
